Skip to content

Conversation

@sanderegg
Copy link
Member

@sanderegg sanderegg commented Jun 16, 2025

What do these changes do?

As spotted with @bisgaard-itis we discovered that running under load some functions would timeout while trying to acquire a DB connection. This should improve that situation.

Related issue/s

How to test

Dev-ops

@sanderegg sanderegg added this to the Engage milestone Jun 16, 2025
@sanderegg sanderegg self-assigned this Jun 16, 2025
@sanderegg sanderegg requested review from GitHK and pcrespov as code owners June 16, 2025 12:17
@sanderegg sanderegg added the a:webserver webserver's codebase. Assigning the area is particularly useful for bugs label Jun 16, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the functions repository to consolidate connection handling, improve transactional usage, and leverage Pydantic’s new from_attributes support for model validation.

  • Wraps all repository operations in pass_or_acquire_connection to reuse or acquire DB connections.
  • Updates transaction_context usage to work with the returned transaction object for both streams and executes.
  • Removes manual dict(row) conversions by enabling Pydantic’s model_config = ConfigDict(from_attributes=True).

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
services/web/server/src/simcore_service_webserver/functions/_functions_repository.py Added pass_or_acquire_connection, adjusted transactions to use transaction, and simplified model_validate calls.
packages/models-library/src/models_library/functions.py Enabled Pydantic’s from_attributes parsing for DB row objects by adding model_config.
Comments suppressed due to low confidence (2)

services/web/server/src/simcore_service_webserver/functions/_functions_repository.py:696

  • [nitpick] The call to check_user_permissions uses a positional conn argument, whereas other calls explicitly name connection=conn. For consistency and clarity, consider using the named parameter connection=conn.
await check_user_permissions(

services/web/server/src/simcore_service_webserver/functions/_functions_repository.py:125

  • [nitpick] get_asyncpg_engine(app) is being called repeatedly in each function. Consider fetching the engine once (e.g., engine = get_asyncpg_engine(app)) at the start of the repository module or function to reduce overhead.
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:

@codecov
Copy link

codecov bot commented Jun 16, 2025

Codecov Report

Attention: Patch coverage is 38.15789% with 94 lines in your changes missing coverage. Please review.

Project coverage is 89.68%. Comparing base (2c40792) to head (ceb430f).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7904      +/-   ##
==========================================
+ Coverage   87.97%   89.68%   +1.70%     
==========================================
  Files        1845     1454     -391     
  Lines       71153    60138   -11015     
  Branches     1220      476     -744     
==========================================
- Hits        62594    53932    -8662     
+ Misses       8207     6085    -2122     
+ Partials      352      121     -231     
Flag Coverage Δ
integrationtests 64.20% <0.67%> (-0.03%) ⬇️
unittests 88.00% <38.15%> (+1.44%) ⬆️
Components Coverage Δ
api ∅ <ø> (∅)
pkg_aws_library ∅ <ø> (∅)
pkg_dask_task_models_library ∅ <ø> (∅)
pkg_models_library 93.25% <100.00%> (+<0.01%) ⬆️
pkg_notifications_library ∅ <ø> (∅)
pkg_postgres_database ∅ <ø> (∅)
pkg_service_integration 69.92% <ø> (ø)
pkg_service_library ∅ <ø> (∅)
pkg_settings_library ∅ <ø> (∅)
pkg_simcore_sdk 85.22% <ø> (+0.17%) ⬆️
agent 96.29% <ø> (ø)
api_server 92.31% <ø> (ø)
autoscaling 96.03% <ø> (ø)
catalog 92.29% <ø> (ø)
clusters_keeper 99.13% <ø> (ø)
dask_sidecar 91.57% <ø> (-0.23%) ⬇️
datcore_adapter 97.94% <ø> (ø)
director 76.73% <ø> (-0.10%) ⬇️
director_v2 91.15% <ø> (+0.01%) ⬆️
dynamic_scheduler 96.69% <ø> (ø)
dynamic_sidecar 90.09% <ø> (ø)
efs_guardian 89.65% <ø> (ø)
invitations 93.00% <ø> (ø)
payments 92.57% <ø> (ø)
resource_usage_tracker 88.79% <ø> (-0.33%) ⬇️
storage 87.85% <ø> (+0.31%) ⬆️
webclient ∅ <ø> (∅)
webserver 87.57% <36.91%> (+0.10%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c40792...ceb430f. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sanderegg
Copy link
Member Author

@mergify queue

@sanderegg sanderegg added the 🤖-automerge marks PR as ready to be merged for Mergify label Jun 16, 2025
@mergify
Copy link
Contributor

mergify bot commented Jun 16, 2025

queue

🟠 Waiting for conditions to match

  • any of: [🔀 queue conditions]
    • all of: [📌 queue conditions of queue default]
      • any of: [🛡 GitHub branch protection]
        • check-neutral = deploy to dockerhub
        • check-skipped = deploy to dockerhub
        • check-success = deploy to dockerhub
      • any of: [🛡 GitHub branch protection]
        • check-neutral = system-tests
        • check-skipped = system-tests
        • check-success = system-tests
      • any of: [🛡 GitHub branch protection]
        • check-neutral = unit-tests
        • check-skipped = unit-tests
        • check-success = unit-tests
      • any of: [🛡 GitHub branch protection]
        • check-neutral = integration-tests
        • check-skipped = integration-tests
        • check-success = integration-tests
      • #approved-reviews-by >= 2 [🛡 GitHub branch protection]
      • #approved-reviews-by>=2
      • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
      • #changes-requested-reviews-by=0
      • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
      • #review-threads-unresolved=0
      • -conflict
      • -draft
      • base=master
      • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
      • label!=🤖-do-not-merge
      • label=🤖-automerge
      • any of: [🛡 GitHub branch protection]
        • check-success = check OAS' are up to date
        • check-neutral = check OAS' are up to date
        • check-skipped = check OAS' are up to date
      • any of: [🛡 GitHub branch protection]
        • check-success = build-test-images (frontend) / build-test-images
        • check-neutral = build-test-images (frontend) / build-test-images
        • check-skipped = build-test-images (frontend) / build-test-images
  • -closed [📌 queue requirement]
  • -conflict [📌 queue requirement]
  • -draft [📌 queue requirement]
  • any of: [📌 queue -> configuration change requirements]
    • -mergify-configuration-changed
    • check-success = Configuration changed

Copy link
Contributor

@wvangeit wvangeit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sanderegg

Copy link
Collaborator

@matusdrobuliak66 matusdrobuliak66 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

Copy link
Contributor

@bisgaard-itis bisgaard-itis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Thanks a lot for the quick fix 👍🏻

Copy link
Collaborator

@matusdrobuliak66 matusdrobuliak66 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks, looks good

@bisgaard-itis
Copy link
Contributor

bisgaard-itis commented Jun 17, 2025

@sanderegg I believe this PR also closes

Can I get you to set this in your PR description? (I didn't do it myself in case you disagree)

Copy link
Member

@pcrespov pcrespov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

Copy link
Contributor

@wvangeit wvangeit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a look again. Looks good to me as far as I can see.

@sanderegg sanderegg force-pushed the i1913/use-one-connection branch from 0059151 to f0db78d Compare June 17, 2025 10:02
@sanderegg sanderegg added the release Preparation for pre-release/release label Jun 17, 2025
@sanderegg sanderegg force-pushed the i1913/use-one-connection branch from 043d7dd to ceb430f Compare June 17, 2025 10:19
@sanderegg
Copy link
Member Author

@mergify queue

@mergify
Copy link
Contributor

mergify bot commented Jun 17, 2025

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at eccf0c0

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
4.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@mergify mergify bot merged commit eccf0c0 into ITISFoundation:master Jun 17, 2025
144 of 149 checks passed
@sanderegg sanderegg deleted the i1913/use-one-connection branch June 17, 2025 10:59
mergify bot pushed a commit that referenced this pull request Jun 17, 2025
@matusdrobuliak66 matusdrobuliak66 mentioned this pull request Jun 20, 2025
92 tasks
@matusdrobuliak66 matusdrobuliak66 mentioned this pull request Aug 5, 2025
88 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-automerge marks PR as ready to be merged for Mergify a:webserver webserver's codebase. Assigning the area is particularly useful for bugs release Preparation for pre-release/release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API server failed unexpectedly (new functions-api related error) Use a single db connection in functions repository methods

7 participants